home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / compguid / printing / textprn / textprin.sx < prev   
Encoding:
Text File  |  1996-05-21  |  2.7 KB  |  84 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. -- Filename:
  3. --      textprin.sx
  4.  
  5. -- Purpose:
  6. --        Defines a method printText on TextPresenter that prints it to
  7. --        multiple pages of a Printer.
  8. method printText self {class TextPresenter} margin units -> (
  9.     local p, oldX, oldY, oldBoundary
  10.     
  11.     -- Create a new Printer and set its margins
  12.     p := new PrinterSpace
  13.     setMargin p margin units
  14.     
  15.     -- Record the old dimensions and location and attach the TextPresenter to the printer
  16.     oldBoundary := self.boundary
  17.     self.boundary := p.boundary
  18.     oldX := self.x;  oldY := self.y
  19.     self.x := self.y := 0
  20.     append p self
  21.     recalcRegion p
  22.     
  23.     -- Set the context to be the PrinterSurface. The TextPresenter might be queried for
  24.     -- metric information before it's told to draw.
  25.     setContext self p.surface p.globalBoundary
  26.     
  27.     if (printerDialog p) do (
  28.         local firstPage, lastPage, \
  29.               newOffset, pageNum
  30.         local defaultPageHeight := self.height
  31.         
  32.         -- Record the page range.
  33.         -- By setting these back to default values, we indicate that
  34.         -- we will deal with them ourselves.
  35.         firstPage := p.firstPage
  36.         p.firstPage := 1
  37.         lastPage := p.lastPage
  38.         p.lastPage := @all
  39.         
  40.         self.offset := newOffset := 0
  41.         pageNum := 1
  42.             
  43.         -- While there's still text to be printed out
  44.         repeat while (newOffset < self.target.size) do (
  45.                         
  46.            self.offset := newOffset
  47.                  
  48.            -- Get the offset of the last visibly complete character on this page
  49.            -- The text for the new page will start right after it.
  50.            newOffset := (getLastVisibleOffset self)
  51.            
  52.            -- Get the position of this character and change the height of the presenter
  53.            -- to match that. Note that the point information is returned in global coordinates
  54.            local lastXY := getPointForOffset self newOffset 
  55.            self.height := (lastXY.y - self.globalboundary.bbox.y1)/self.globaltransform.d
  56.  
  57.            -- If the current page is within the correct 
  58.            -- range, then print it
  59.            if ((pageNum >= firstPage) and \
  60.                ((lastPage = @all) or (pageNum <= lastPage))) do (
  61.  
  62.                -- Take a snapshot of the current page 
  63.                printFrame p
  64.  
  65.                -- Flush the current page and move on to a new one
  66.                flushPage p
  67.             )
  68.  
  69.             pageNum := pageNum + 1
  70.             newOffset := newOffset + 1
  71.             -- Restore to standard height            
  72.             self.height := defaultPageHeight 
  73.          )
  74.  
  75.         flushDocument p
  76.     )
  77.     
  78.     emptyout p
  79.     self.offset := 0
  80.     self.x := oldX; self.y := oldY
  81.     self.boundary := oldBoundary
  82. )
  83. -->>>
  84.